package net.sky.oa.dao.talkpark.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.htsoft.core.web.paging.PagingBean;

import net.sky.oa.dao.SkyBaseDaoImpl;
import net.sky.oa.dao.talkpark.TalBoxDao;
import net.sky.oa.model.TalBox;

@SuppressWarnings("unchecked")
@Repository
public class TalBoxDaoImpl extends SkyBaseDaoImpl<TalBox> implements TalBoxDao {
	
	public TalBoxDaoImpl(){
		super.setPersistType(TalBox.class);
	}

	public List<TalBox> findAllTalbox() {
	   String hql="from TalBox tb";
		return findByHql(hql);
	}

	//根据收件的用户查找文件
	public List<TalBox> getTalboxByUserId(final Long UserId,final int type,final String title,final String cratetime,PagingBean pb){
		     List list=new ArrayList();
			 StringBuffer buffer=new StringBuffer("select tb from TalBox tb," +
			 		"TalBoxUser tbu where 1=1 and tb.id=tbu.box.id");
			 try {
				    if(UserId!=-1){
						buffer.append(" and tbu.user.id =?");
						list.add(UserId);
					}if(type!=-1){
						buffer.append(" and tb.type= ?");
					    list.add(type);
					}if(null!=title && !"".equals(title)){
						buffer.append(" and tb.title like ?");
						list.add("%"+title+"%");
					
					}if(cratetime!=null && (!("".equals(cratetime)))){
						buffer.append(" and to_char(tb.createtime,'yyyy-MM-dd')=?");
						list.add(cratetime);
					}
					buffer.append(" order by tb.createtime desc");
				return findByHql(buffer.toString(), list.toArray(), pb);
			} catch (Exception e) {
				 e.printStackTrace();
				 return null;
			}
				
		
	}

}
